# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=lapack

pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.6.0
pkgrel=1
arch=('any')
pkgdesc="Linear Algebra PACKage (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-gcc-libgfortran")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-gcc-fortran")
options=('strip' 'staticlibs')
license=('LGPL')
url="http://www.netlib.org/lapack"
source=("http://www.netlib.org/${_realname}/${_realname}-${pkgver}.tgz")
sha256sums=('a9a0082c918fe14e377bbd570057616768dca76cbdc713457d8199aaa233ffc3')

build()
{
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null

  pushd ${MINGW_PREFIX} > /dev/null
  export PREFIX_DEPS=`pwd -W`
  popd > /dev/null

  cd "$srcdir"
  mkdir -p build-${CARCH} && cd build-${CARCH}
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
    -DCMAKE_Fortran_COMPILER:PATH=${PREFIX_DEPS}/bin/gfortran.exe \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=ON \
    -DCMAKE_NEED_RESPONSE=ON \
    -DBUILD_TESTING=OFF \
    ../${_realname}-${pkgver}
  make

  cd "$srcdir"
  mkdir -p build-${CARCH}s && cd build-${CARCH}s
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
    -DCMAKE_Fortran_COMPILER:PATH=${PREFIX_DEPS}/bin/gfortran.exe \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=OFF \
    -DBUILD_TESTING=OFF \
    ../${_realname}-${pkgver}
  make
}

package()
{
  cd "$srcdir/build-${CARCH}s"
  make install # DESTDIR="$pkgdir"
  cd "$srcdir/build-${CARCH}"
  make install # DESTDIR="$pkgdir"
}
